<?php

namespace Xin\Logger\Hyperf;

use Hyperf\Framework\Logger\StdoutLogger as HyperfStdoutLogger;
use Xin\Logger\Contracts\EnableTimePrint;
use Xin\Logger\EnableTimePrintable;

class StdoutLogger extends HyperfStdoutLogger implements EnableTimePrint
{
    use EnableTimePrintable;

    /**
     * {@inheritdoc}
     */
    public function log($level, $message, array $context = []): void
    {
        foreach ($context as $key => $value) {
            $context[$key] = is_object($value) || is_array($value) ? json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : $value;
        }

        parent::log($level, $this->getTimePrefix().$message, $context);
    }


}
